clear all

// SET MACROS
global Input  "Y:/limited/Michigan_CTE/funding_change/data_final"
global Output "Y:/limited/Michigan_CTE/funding_change/output/figures"

qui include "Y:/limited/Michigan_CTE/funding_change/code/analyze/figures/00_colors.do"

local demographics "female black hisp another_race sped lep econdis"
local academics "test_avg_g8 test_avg_sq_g8 test_avg_g8_imp attendance_g8 attendance_g8_imp"

// LOAD DATA
use $Input/compiled_student_analysis_data.dta

keep if grad_year >= 2012
replace c2014 = 0

gen cohort = .

gen city1_over_time     = .
gen city1_over_time_l95 = .
gen city1_over_time_u95 = .
gen city2_over_time     = .
gen city2_over_time_l95 = .
gen city2_over_time_u95 = .
gen city3_over_time     = .
gen city3_over_time_l95 = .
gen city3_over_time_u95 = .
gen city4_over_time     = .
gen city4_over_time_l95 = .
gen city4_over_time_u95 = .

forvalues y = 1/4 {
  eststo: reghdfe cte_comp c2012-c2019 `demographics' `academics' if district_urbanicity == `y' , a(district) cluster(district)
  
  local i = 1
  forvalues x = 2012/2019 {
    replace city`y'_over_time = 100 * _b[c`x'] in `i'
    replace city`y'_over_time_l95 = 100 *  _b[c`x'] - (invttail(e(df_r), 0.025) * 100 * _se[c`x']) in `i'
    replace city`y'_over_time_u95 = 100 *  _b[c`x'] + (invttail(e(df_r), 0.025) * 100 * _se[c`x']) in `i'
    replace cohort = `x' if missing(cohort) in `i'
    local ++i
  }
}

keep cohort city1* city2* city3* city4*
drop if missing(cohort)

// DRAW GRAPH
tw (rarea city4_over_time_l95 city4_over_time_u95 cohort, color("$c4%30") lwidth(none)) ///
   (rarea city3_over_time_l95 city3_over_time_u95 cohort, color("$c3%30") lwidth(none)) ///
   (rarea city2_over_time_l95 city2_over_time_u95 cohort, color("$c2%30") lwidth(none)) ///
   (rarea city1_over_time_l95 city1_over_time_u95 cohort, color("$c1%30") lwidth(none)) ///
   (connected city4_over_time city3_over_time city2_over_time city1_over_time cohort, sort ///
   mc("$c4" "$c3" "$c2" "$c1") ///
   m(S D T O) ///
   lc("$c4" "$c3" "$c2" "$c1") ///
   lp(dash_dot shortdash dash solid)), ///
   scale(1.1) ///
    xline(2014.5 2015.5, lc(gs12) lp(-)) ///
   yline(0, lc(gs11)) ///
   text(17.9 2014.5 "Funding" "increased," "new formula" "announced", placement(0) color(black) box bcolor(white) margin(b=1)) ///
   text(19.1 2015.5 "New" "formula" "applied", placement(0) color(black) box bcolor(white) margin(t=2 b=1)) ///
   xlabel(2012/2019) ///
   xtitle(" " "Cohort Graduation Year", margin(t=2)) ///
   ylabel(-5(5)20, angle(0) glc(gs13) glw(vthin) glp(shortdash) gmax) ///
   ytitle("Percentage Point Change" " ") ///
   legend(order(8 7 6 5) label(8 "Urban") label(7 "Suburban") label(6 "Town") label(5 "Rural") rows(1) symxsize(7) region(lstyle(none))) ///
   graphregion(color(white)) bgcolor(white) ///
   xsize(7) ysize(3.25) ///
	 scheme(s2color)


// EXPORT GRAPH


graph save $Output/05a_reg_urbanicity.gph, replace
*graph export $Output/reg_urbanicity.png, replace
